


//setInterval: the function will be executed for every given milliseconds
//for example: setInterval(sample,3000) for every 3000milliseconds the
//function sample will be executed

var c=1;
var time=setInterval(countTime,2000);
function countTime(){
    document.getElementById('text').innerHTML=c;
    c++;
    if(c==3){
        alert("Alert fired after two seconds");
        clearInterval(time);
    }
}